﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2013_ece_csharp_snake
{
    public partial class DialogCo : Form
    {
        //private ConnexionReceiveMulti receiver;
        private ConnectionInformation coInf;


        public DialogCo(ConnectionInformation coInf)
        {
            //this.receiver = receiver;
            this.coInf = coInf;

            InitializeComponent();
        }

        // Refresh Button
        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = dataGridView1.RowCount; i < coInf.hostsIP.Count; i++)
                dataGridView1.Rows.Add(new DataGridViewRow());


            for (int i = 0; i < coInf.hostsIP.Count; i++)
            {
                dataGridView1.Rows[i].Cells[0].Value = coInf.hostsIP[i];
                dataGridView1.Rows[i].Cells[1].Value = coInf.hostsName[i];
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedCells.Count > 0 || dataGridView1.SelectedRows.Count > 0)
            {
                if (dataGridView1.SelectedCells.Count > 0)
                    coInf.playerIP = (String)dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[0].Value;
                else if (dataGridView1.SelectedRows.Count > 0)
                    coInf.playerName = (String)dataGridView1.Rows[dataGridView1.SelectedRows[0].Index].Cells[0].Value;

                coInf.eventCo.Set();

                Close();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
